var t = getApp()
Page({
  data: {
    user: '',
    pass: '',
    isPass:true,
    openid:'',
  },
  onLoad: function(){
    // 获取openid
    var that = this;
    wx.login({
      success(e){
        t.request('/Manage/Management/getOpenid',{code: e.code},function(event){
          wx.setStorageSync('openid', event.result.openid);
            that.setData({
              openid:event.result.openid,
            })
        })
      }
    })
  },
  onShow: function () {},
  // 获取输入账号 
  usernameInput: function (e) {
    this.setData({
      user: e.detail.value
    })
  },
  // 获取输入密码 
  passinput: function (e) {
    console.log(e)
    this.setData({
      pass: e.detail.value
    })
  },

  // 登录处理
  login: function () {
    var that = this;
    if (that.data.user.length == 0 || that.data.pass.length == 0) {
      wx.showToast({
        title: '账号或密码不能为空',
        icon: 'none',
        duration: 2000
      })
    } else {
      var that=this
      t.request('/Manage/Management/login',{user: that.data.user,app_password: that.data.pass,openid:that.data.openid},function(e){
        console.log(e);
          if (e.code == "200") {
            wx.setStorageSync('user_id', e.result.user.u_id);
            wx.setStorageSync('user', e.result.user);
            t.globalData.b_id = e.result.user.b_id
            wx.setStorageSync('role_id', e.result.user.role_id);
            wx.switchTab({
              url: '/pages/index/index',
            })
          } else {
            t.showError(e.msg);
            // wx.showToast({
            //   title: e.message,
            //   icon: 'none',
            //   duration: 2000
            // })
          }
      })
    }
  },
  onPullDownRefresh: function () {
    console.log('onPullDownRefresh')
    // 3秒模拟数据加载
    setTimeout(function () {
      // 不加这个方法真机下拉会一直处于刷新状态，无法复位
      wx.stopPullDownRefresh()
    }, 2000)
  },
  // 隐藏、显示密码
  changIsPass:function(){
    let isPass = !this.data.isPass;
    console.log('isPass',isPass)
    this.setData({
      isPass
    })
  },

})